package com.sample.Service;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ServiceActivity extends Activity implements OnClickListener{
	Service appsService;
	Button button1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button1=(Button)findViewById(R.id.button1);
        button1.setOnClickListener(this);
        bindService(new Intent(this, ServiceTest.class), onService, Context.BIND_AUTO_CREATE);
    }
    public void onClick(View v){
    appsService.startService(new Intent(this, ServiceTest.class));	
    }
    private ServiceConnection onService=new ServiceConnection(){
    public void onServiceConnected(ComponentName className, IBinder	rawBinder){
    appsService=((ServiceTest.LocalBinder)rawBinder).getService();	
    }
public void onServiceDisconnected(ComponentName className){
    appsService=null;	
    }};

}